package com.atguigu.juc.juc20210301;


import jdk.nashorn.internal.codegen.CompilerConstants;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;


class MyThread implements Callable<String>
{
    @Override
    public String call() throws Exception
    {
        System.out.println("----come in");
        //暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
        return "hello 0301javawh";
    }
}



/**
 * @auther zzyy
 * @create 2020-03-28 16:30
 * java里面，第三种获得多线程的方式
 * 一个新的接口，Callable
 * 1 what
 * 2 why
 * 3 how ---难
 */
public class CallableDemo
{
    public static void main(String[] args) throws Exception//main + t1
    {
        FutureTask<String> futureTask = new FutureTask<>(new MyThread());
        new Thread(futureTask,"t1").start();

        FutureTask<String> futureTask2 = new FutureTask<>(new MyThread());
        new Thread(futureTask2,"t2").start();


        System.out.println(Thread.currentThread().getName()+"\t"+"---do..... in");

        System.out.println(futureTask.get());
    }
}
